package com.lzq.service;

import java.sql.Connection;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.sql.Statement;
import java.util.ArrayList;
import java.util.List;

import javax.sql.DataSource;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import com.lzq.domain.TCourse;

@Service
public class MyCourseService {

	@Autowired
	private DataSource dataSource;

	public List<TCourse> getAllCourse() throws SQLException {

		Connection conn = dataSource.getConnection();
		Statement state = conn.createStatement();
		ResultSet rs = state.executeQuery("select id,name,mark from course");
		List<TCourse> result = new ArrayList<>();
		while (rs.next()) {
			result.add(new TCourse((Long) rs.getObject(1), (String) rs.getObject(2), (int) rs.getObject(3)));

		}
		return result;

	}
}
